package com.house.smallbug;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.house.smallbug.house.HosueFragment;
import com.house.smallbug.people.PeopleFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn_house,btn_people;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager=(ViewPager)findViewById(R.id.viewPager);
        btn_house=(Button)findViewById(R.id.btn_house);
        btn_people=(Button)findViewById(R.id.btn_people);

        List<Fragment> list=new ArrayList<>();
        list.add(new HosueFragment());
        list.add(new PeopleFragment());
        FragmentAdapter adapter=new FragmentAdapter(getSupportFragmentManager(),list);
        viewPager.setAdapter(adapter);

        addListenser();
    }

    private void addListenser(){
        btn_house.setOnClickListener(this);
        btn_people.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_house:
                viewPager.setCurrentItem(0);
                break;
            case R.id.btn_people:
                viewPager.setCurrentItem(1);
                break;
            default:
                break;
        }
    }
}
